PROMPT.TXT prompt and related tips Sun 4-Sep-94 ================================== All rights reserved Copyright (c) 1993, 1994 by Timo Salmi .................................................................. Prof. Timo Salmi Co-moderator of comp.archives.msdos.announce Moderating at garbo.uwasa.fi anonymous FTP archives 128.214.87.1 Faculty of Accounting & Industrial Management; University of Vaasa Internet: ts@uwasa.fi BBS +(358)-61-3170972; FIN-65101, Finland .................................................................. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ This file belongs to TSBAT*.ZIP. Please do not distribute ³ ³ this prompt.txt file separately! ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ 1) If you have programs that can shell to dos it would be nice to know whether you currently are in a dos shell or not. Else you might call the same program again from the shell and eventually run out of memory. There is a rather straight-forward trick for this. Assume that your program is called prog.exe. You can always call the program from a batch, say pro.bat. Include the following lines in your batch: set _prompt=%prompt% set prompt=%_prompt%[in shell or whatever text] prog %1 %2 %3 %4 %5 %6 %7 %8 %9 set prompt=%_prompt% set prompt= The method will not work or will produce unexpected results if the program itself manipulates the prompt when shelling to Dos. Some (usually advanced) programs do. Another trick to avoid double loading is shown in the following skeleton if "%_loaded%"=="yes" exit set _loaded=yes prog %1 %2 %3 %4 %5 %6 %7 %8 %9 set _loaded= 2) A frequently asked question about ansi.sys is now does one use it to redefine keyboard keys. Here is an example which redefines the F1 key invoke the directory "dir" command, the F2 key to invoke the "dir/w" command, and the F3 to type the Scandinavian letter „. prompt $e[0;59;"dir";13p prompt $e[0;60;"dir/w";13p prompt $e[0;61;"„"p prompt $p$g The last line is needed to restore the prompt in its usual format (which I have as $p$g). To cancel the definitions apply prompt $e[0;59;;p prompt $e[0;60;;p prompt $e[0;61;;p prompt $p$g This system requires that you have ansi.sys loaded in your config.sys file device=c:\dos\ansi.sys A related FAQ (Frequently Asked Question) is how to exchange the . and , keys. here is how to do that @echo [",";"."p[".";","p To reverse the effect, apply @echo [",";","p[".";"."p This trick will not work for exchanging the CTRL and SHIFT keys. They are not mappable this way. Note that ansi.sys replacements like zansi.sys (which I normally use myself) do not have the key-redefinition feature. This has one advantages, that is protecting you against the so-called ansi bombs. The 0;59 pair defines F1 because it is that key's scan code. To get the scan codes of the different keys you need either a scan code table or a program that gives the scan code of the key you have pressed. One such program is SCANCODE.EXE in garbo.uwasa.fi:/pc/ts/ tsbase11.zip (or whatever version number is the current). 3) You can devise quite complicated ansi prompts to do flashy things although much of this is rather computer entertainment than serious usage. Let look at some examples My ordinary prompt is the simple prompt $p$g which displays the directory followed bu the > sign. Furthermore I use bright yellow on black, but for that I apply echo [40;33;1m Let's build from that. prompt $d $t$_$p$g Gives the date and the time on the first line ($d $t), then on the second ($_) gives the current directory ($p) and the > sign ($g). Lets take a little more complicated example next: prompt $e[s$e[1;69H$t$h$h$h$e[u$p$g This is of of the basic prompt tricks, and it puts the time in the upper right corner of the screen. First the current cursor postion is stored ($e[s); the cursor is moved to row 1, column 69 ($e[1;69H) the time is displayed ($t); the hundredths of a second are deleted ($h$h$h); the original cursor position is restored ($e[u); and finally the current directory and the > sign are displayed ($p$g). The next obvious step is to display the time in some garish reverse. For the normal part of the prompt lets use my own default which is bright yellow on black ($e[40;33;1m). prompt $e[s$e[1;69H$e[41;32;1m$t$e[40;33;1m$h$h$h$e[u$p$g The time is displayed in bright green on red ($e[41;32;1m). The interpretation of the following prompt is left as an exercise: prompt $e[s$e[H$e[43;30m$e[KDirectory $p $d $t $h$h$h$h $v $e[40;33;1m$e[2;1H$e[K$e[u$p$g Note that you must have everything on one line only. The wrap here is just for readability. One example of an "entertainment" prompt just to give the general idea: prompt $e[s$_$e[40;37mÛÛ$e[34mÛÛ$e[37mÛÛÛÛ$_$e[34mÛÛÛÛÛÛÛÛ $e[40;37m$_ÛÛ$e[34mÛÛ$e[37mÛÛÛÛ$e[40;33m $p$g Note that you must have everything on one line only. The wrap here is just for readability. The difference in using the echo and the prompt for setting the screen colors is that the echo is invoked only when you apply it, but the prompt is called each time the dos prompt appears. 4) If you are having problems you can "debug" your prompt by giving the set command in MsDos which displays your environment variables including the prompt variable.